package  com.hobbit.analyze.analyzers
{
	
	import com.hobbit.analyze.base.LoadItem;
	
	import flash.utils.Dictionary;

	/**
	 *  解析器字典
	 * 
	 */	
	public class AnalyzeDictionary
	{
		private static var instance:AnalyzeDictionary;
		private var analyzeDic:Dictionary;
		
		public function AnalyzeDictionary()
		{
			if(instance==null)
			{
				analyzeDic = new Dictionary();
				
				analyzeDic[LoadItem.TYPE_XML] = XmlAnalyze;
				analyzeDic[LoadItem.TYPE_SWF] = SwfAnalyze;
				analyzeDic[LoadItem.TYPE_JSON] = JsonAnalyze;
				analyzeDic[LoadItem.TYPE_SHEET] = SheetAnalyze;
				analyzeDic[LoadItem.TYPE_UI] = UiAnalyze;
				//add
			}else
			{
				throw new Error("实例AnalyzeDictionary出错");
			}
		}
		
		public static function getInstance():AnalyzeDictionary
		{
			if(!instance)
			{
				instance = new AnalyzeDictionary();
			}
			return instance;
		}
		
		/**
		 *注册一个解析器 
		 * @param key
		 * @param analyzeClass
		 * 
		 */		
		public function registerAnalyze(key:String,analyzeClass:Class):void
		{
			if(!analyzeDic[key])
			{
				analyzeDic[key] = analyzeClass;
			}
		}
		
		/**
		 *获取已有解析器 
		 * @param key
		 * @return 
		 *  
		 */		
		public function getAnalyze(key:String):IAnalyze
		{
			if(analyzeDic[key] is Class)
			{
				analyzeDic[key] = new (analyzeDic[key] as Class)();
			}
			return analyzeDic[key];
		}
	}
}